<template>
    <div ref="line" class="line1"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: {
    xData: {
      type: Array,
      default: () => []
    },
    yData: {
      type: Array,
      default: () => []
    }
  },
//   data() {
//     return {
//       myChart: null
//     };
//   },
  methods: {
    draw() {
    //   debugger;
      //   if (this.myChart === null) {
      //     this.myChart = echarts.init(this.$refs.line);
      //   }
      var myChart = echarts.init(this.$refs.line);
      // 配置（绘制图表）
      myChart.setOption({
        legend: {},
        title: {
          text: "订单统计"
        },
        tooltip: {},
        xAxis: {
          data: this.xData
        },
        yAxis: {},
        // 画折线图
        series: this.yData.map(item => {
          item.type = "line";
          return item;
        })
      });
    }
  },
  watch: {
    xData: {
      handler: function() {
        this.draw();
      },
      deep: true
    }
  }
};
</script>

<style lang="less" scoped>
.line1 {
  width: 100%;
  height: 100%;
}
</style>